//
//  WDADHeadView.m
//  Zhihuijinfu
//
//  Created by 王笛 on 2016/12/23.
//  Copyright © 2016年 王笛. All rights reserved.
//

#import "WDADHeadView.h"
#import "WDLinkMessage.h"
#import "UIColor+WDColorExtension.h"

@interface WDADHeadView ()
@property(nonatomic, weak) UIImageView *iconView;
@property(nonatomic, weak) UILabel *nameLabel;
@property(nonatomic, weak) UILabel *cityLbel;
@end
@implementation WDADHeadView

+ (instancetype)adHeadView
{
    return [[self alloc] init];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = WDNavSeleColor;
        
        UIImageView *iconView = [[UIImageView alloc] init];
        
        [self addSubview:iconView];
        
        self.iconView = iconView;
        
        [iconView makeConstraints:^(MASConstraintMaker *make) {
            
            make.centerX.equalTo(self.centerX);
            
            make.bottom.equalTo(-95);
            
            make.width.height.equalTo(50);
            
        }];
        
        iconView.layer.cornerRadius = 25;
        
        iconView.clipsToBounds = YES;
        
        
        UILabel *nameLabel = [[UILabel alloc] init];
        
        nameLabel.textColor = [UIColor whiteColor];
        
        nameLabel.font = [UIFont systemFontOfSize:16];
        
        nameLabel.textAlignment = NSTextAlignmentCenter;
        
        [self addSubview:nameLabel];
        
        self.nameLabel = nameLabel;
        
        [nameLabel makeConstraints:^(MASConstraintMaker *make) {
            
            make.centerX.equalTo(self.centerX);
            
            make.top.equalTo(iconView.bottom).offset(15);
        }];
        
        
        UILabel *cityLabel = [[UILabel alloc] init];
        
        cityLabel.textColor = [UIColor getColorFromString:@"#ccffffff"];
        
        cityLabel.font = [UIFont systemFontOfSize:12];
        
        cityLabel.textAlignment = NSTextAlignmentCenter;
        
        [self addSubview:cityLabel];
        
        self.cityLbel = cityLabel;
        
        [cityLabel makeConstraints:^(MASConstraintMaker *make) {
            
            make.centerX.equalTo(self.centerX);
            
            make.top.equalTo(nameLabel.bottom).offset(3);
        }];
        
    }
    return self;
}

- (void)setLinkMessage:(WDLinkMessage *)linkMessage
{
    _linkMessage = linkMessage;
    
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:linkMessage.image_url] placeholderImage:[UIImage imageNamed:@"defaultIcon"]];
    
    self.nameLabel.text = linkMessage.name;
    
    self.cityLbel.text = linkMessage.work_city_name;
}

@end
